﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BRS.BidModule
{
    public partial class UpdateProject : Form
    {
        Entities brs = new Entities();
        int pid;
        Users us = new Users();
        public UpdateProject()
        {
            InitializeComponent();
        }

        public UpdateProject(int proid)
        {
            InitializeComponent();
            pid = proid;
            var project = brs.tb_Project.Find(proid);
            if (project != null)
            {
                comboBox1.DisplayMember = "Name";//控件显示的列名  
                comboBox1.ValueMember = "Name";//控件值的列名  
                comboBox1.DataSource = brs.TenderMsg.Where(p => p.Type == "招标人").OrderBy(p => p.AddTime).ToList();
                comboBox2.DisplayMember = "Name";//控件显示的列名  
                comboBox2.ValueMember = "Name";//控件值的列名  
                comboBox2.DataSource = brs.TenderMsg.Where(p => p.Type == "招标代理").OrderBy(p => p.AddTime).ToList();
                this.textBox1.Text = project.ProjectName;
                this.textBox2.Text = project.ProjectCode;
                this.textBox3.Text = project.Note;
                this.textBox4.Text = project.Leader;
                this.comboBox1.SelectedValue= project.Tender; project.Deadline.ToString();
                this.comboBox2.SelectedValue = project.TenderAgent;
                this.dateTimePicker1.Value = project.Deadline.Value;
                this.checkBox2.Checked = project.Enabled.Value;
                this.label10.Text = proid.ToString();

            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var pro = brs.tb_Project.Find(pid);
            if (pro != null)
            {
                pro.ISID = int.Parse(label10.Text);
                pro.ProjectName = this.textBox1.Text;
                pro.ProjectCode = this.textBox2.Text;
                //pro.CreateDate = DateTime.Now;       
                //pro.Leader =us.UserName;// 创建项目使用用户码来创建，此地可以根据需要修改，要求用号码应该唯一
                pro.IsDone = this.checkBox1.Checked;
                pro.Enabled = this.checkBox2.Checked;
                pro.Deadline = dateTimePicker1.Value;
                pro.Deaddate = dateTimePicker1.Value.Date.AddDays(1);
                pro.Note = this.textBox3.Text;
                pro.Tender = this.comboBox1.SelectedValue.ToString() == null ? this.comboBox1.Text : this.comboBox1.SelectedValue.ToString();
                pro.TenderAgent = this.comboBox2.SelectedValue.ToString() == null ? this.comboBox2.Text : this.comboBox2.SelectedValue.ToString();
                if (brs.SaveChanges() > 0) { MessageBox.Show("修改成功！"); };
            }

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void label10_Click(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }


    }
}
